import http from '../../utils/http.js'

export function getPayOrder(payMethod,id){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/pay/order',
		   method:'POST',
		   data:{
			   payMethod: payMethod,
			   id:id
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function payRequest(provider,orderInfo){
	return new Promise((resolve,reject)=>{
		uni.requestPayment({
			provider:provider,
			orderInfo:orderInfo,
			success:(res)=>{
				resolve(res)
			},
			fail: (error) => {
				reject(error)
			}
		})
	})
}

export function wxPayRequst(result){
	return new Promise((resolve,reject)=>{
		uni.requestPayment({
			nonceStr: result.nonceStr,
			package: result.package,
			paySign: result.paySign,
			timeStamp: result.timeStamp,
			signType: result.signType,
			success() {
				resolve()
			},
			fail() {
				reject('支付错误')
			}
		})
	})
}